//
//  HNStrengtheningClassApplicationCountListCell.m
//  优学荟管理系统
//
//  Created by edz on 2017/11/27.
//  Copyright © 2017年 星道三好. All rights reserved.
//

#import "HNStrengtheningClassApplicationCountListCell.h"
#import "HNStrengtheningClassApplicationApplyElementView.h"

@implementation HNStrengtheningClassApplicationCountListCell
{
    __weak IBOutlet UILabel *_Title;
    __weak IBOutlet UILabel *_State;
    __weak IBOutlet UIView *_ApplyView;
    __weak IBOutlet NSLayoutConstraint *_ApplyViewHeight;
    __weak IBOutlet UIButton *_StrengtheningClassListBtn;
    __weak IBOutlet NSLayoutConstraint *_ContentViewHeight;
}

- (void)setModel:(HNStrengtheningClassApplicationCountListModel *)Model {
    
    _Model = Model;
    
    _Title.text = Model.name;
    _State.text = [Model.num isEqualToNumber:@0] ? @"未开课" : @"已开课";
    _StrengtheningClassListBtn.hidden = [Model.num isEqualToNumber:@0] ? YES : NO;
    
    // 设置要素的View
    [self SetupApplyViewOfModel:Model];
}

/** 设置要素的View */
- (void)SetupApplyViewOfModel:(HNStrengtheningClassApplicationCountListModel *)Model {
    
    [Model.setCourseComments enumerateObjectsUsingBlock:^(HNStrengtheningApplicationApplyElementModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        HNStrengtheningClassApplicationApplyElementView *View = [[HNStrengtheningClassApplicationApplyElementView alloc] initWithTitle:obj.content andNum:obj.count];
        [_ApplyView addSubview:View];
        [View mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.top.equalTo(_ApplyView.mas_top).offset(40*idx);
            make.left.equalTo(_ApplyView);
            make.right.equalTo(_ApplyView);
            make.height.equalTo(@40);
        }];
    }];
    _ApplyViewHeight.constant += (Model.setCourseComments.count * 40);
    _ContentViewHeight.constant += (_ApplyViewHeight.constant);
    [self layoutIfNeeded];
}

/** 增加加强课 */
- (IBAction)Action_AddStrengtheningClass:(UIButton *)sender {
    
    self.Delegate ? [self.Delegate HNStrengtheningClassApplicationCountListCell:self ActionWithOpenStrengtheningClass:sender andModel:self.Model] : nil;
}

/** 加强课列表 */
- (IBAction)Action_List:(UIButton *)sender {
    
    self.Delegate ? [self.Delegate HNStrengtheningClassApplicationCountListCell:self ActionWithStrengtheningClassList:sender andModel:self.Model] : nil;
}
@end
